#include <bits/stdc++.h>

using namespace std;

//https://leetcode-cn.com/contest/weekly-contest-208
/**

 */ 
class Solution {
public:
    int minOperationsMaxProfit(vector<int>& customers, int boardingCost, int runningCost) {
        int waitnum=0,runnum=0,len=customers.size(),maxl=0,minx=-1;
        int i=0,curround=1;
        while(i<len || waitnum>0){
            if(i<len)
                waitnum+=customers[i];

            if(waitnum>=4){
                waitnum-=4;
                runnum+=4;
            }else if(waitnum>=0){
                runnum+=waitnum;
                waitnum=0;
            }
            int t=runnum*boardingCost-curround*runningCost;
    // cout << curround << " " << waitnum << " " <<  runnum <<"*"<< boardingCost<< "-" << curround<< "*"<<runningCost<<endl;
            if(t>maxl){
                maxl=t;
                minx=curround;
            }
            if(i<len){
                i++;
            }
            curround++;
        }
        return minx;
    }
};

int main(){
#ifdef DEBUG
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

    Solution s;
    vector<int> v={8,3};
    cout << s.minOperationsMaxProfit(v,5,6)<<endl;

    return 0;
}